package com.chf.job.controller;

import com.chf.job.common.Const;
import com.chf.job.common.ServerResponse;
import com.chf.job.pojo.Company;
import com.chf.job.pojo.User;
import com.chf.job.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class CompanyController {
    @Autowired
    private CompanyService companyService;

    /**
     * 添加更新公司信息
     * @param company
     * @param request
     * @return
     */
    @RequestMapping(value = "company/updateCompany.html", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse addCompany(Company company, HttpServletRequest request) {
        User user = (User) request.getSession(true).getAttribute(Const.CURRENT_USER);
        int result = companyService.updateCompany(company, user.getEmail());
        if (result > 0) {
            return ServerResponse.createBySuccess("成功", Const.ADD_COMPANY);
        }
        return ServerResponse.createByErrorMessage("失败");
    }

    /**
     * 添加公司详细介绍
     */
    @RequestMapping(value = "company/addCompanyIntroduce.html", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse addCompanyIntroduce(Company company, HttpServletRequest request) {
        User user = (User) request.getSession(true).getAttribute(Const.CURRENT_USER);
        int result = companyService.addCompanyIntroduce(company, user.getEmail());
        if (result > 0) {
            return ServerResponse.createBySuccess("成功", Const.RELEASE_POST);
        }
        return ServerResponse.createByErrorMessage("失败");
    }
}
